package com.summer.safe.system.entity;


import com.google.common.collect.Lists;
import com.summer.safe.base.BaseEntity;
import org.apache.commons.lang3.StringUtils;

import java.util.List;

/**
 * 角色Entity
 *
 */
public class Role extends BaseEntity<Role> {

    private static final long serialVersionUID = 1L;

    /**
     * 角色名称
     */
    private String name;
    /**
     * 权限类型
     */
    private String roleType;
    /**
     * 数据范围
     */
    private String dataScope;
    /**
     * 是否是可用
     */
    private String useable;
    /**
     * 根据用户ID查询角色列表
     */
    private User user;
    /**
     * 拥有菜单列表
     */
    private List<Menu> menuList = Lists.newArrayList();

    /**
     * 拥有菜单列表
     */
    private List<Office> officeList = Lists.newArrayList();


    // 数据范围（1：所有数据；2：所在部门及以下数据；3：部门数据；4：个人数据；5：自定义）
    public static final String DATA_SCOPE_ALL = "1";
    public static final String DATA_SCOPE_OFFICE = "2";
    public static final String DATA_SCOPE_DEPT = "3";
    public static final String DATA_SCOPE_SELF = "4";
    public static final String DATA_SCOPE_ENTER= "5";


    public Role() {
        super();
        /*this.dataScope = DATA_SCOPE_SELF;*/
        this.useable= "0";
    }

    public Role(String id) {
        super(id);
    }

    public Role(User user){
        this();
        this.user = user;
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRoleType() {
        return roleType;
    }

    public void setRoleType(String roleType) {
        this.roleType = roleType;
    }

    public String getDataScope() {
        return dataScope;
    }

    public void setDataScope(String dataScope) {
        this.dataScope = dataScope;
    }

    public String getUseable() {
        return useable;
    }

    public void setUseable(String useable) {
        this.useable = useable;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<Menu> getMenuList() {
        return menuList;
    }

    public void setMenuList(List<Menu> menuList) {
        this.menuList = menuList;
    }

    public List<Office> getOfficeList() {
        return officeList;
    }

    public void setOfficeList(List<Office> officeList) {
        this.officeList = officeList;
    }

    public void setMenuIds(String menuIds) {
        menuList = Lists.newArrayList();
        if (menuIds != null){
            String[] ids = StringUtils.split(menuIds, ",");
            setMenuIdList(Lists.newArrayList(ids));
        }
    }

    public void setMenuIdList(List<String> menuIdList) {
        menuList = Lists.newArrayList();
        for (String menuId : menuIdList) {
            Menu menu = new Menu();
            menu.setId(menuId);
            menuList.add(menu);
        }
    }

    public String getMenuIds() {

        return StringUtils.join(getMenuIdList(), ",");
    }

    public List<String> getMenuIdList() {
        List<String> menuIdList = Lists.newArrayList();
        for (Menu menu : menuList) {
            menuIdList.add(menu.getId());
        }
        return menuIdList;
    }
    public void setOfficeIds(String menuIds) {
        menuList = Lists.newArrayList();
        if (menuIds != null){
            String[] ids = StringUtils.split(menuIds, ",");
            setMenuIdList(Lists.newArrayList(ids));
        }
    }

    public void setOfficeIdList(List<String> officeIdList) {
        officeList = Lists.newArrayList();
        for (String menuId : officeIdList) {
            Office office = new Office();
            office.setId(menuId);
            officeList.add(office);
        }
    }

    public String getOfficeIds() {

        return StringUtils.join(getOfficeIdList(), ",");
    }

    public List<String> getOfficeIdList() {
        List<String> officeIdList = Lists.newArrayList();
        for (Office office : officeList) {
            officeIdList.add(office.getId());
        }
        return officeIdList;
    }

}
